package com.xmy.aboutThread;

import java.util.ArrayList;
import java.util.concurrent.*;

// Callable、Future与FutureTask
// run() 方法有返回值，提供了异步的一种方式
public class Demo2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService es = Executors.newCachedThreadPool();

        Task task0 = new Task();

        Future<Integer> result = es.submit(task0);

        System.out.println(result.get());

        System.out.println(Thread.currentThread().getState().toString());

    }
}

class Task implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {

        Thread.sleep(1000);

        System.out.println(Thread.currentThread().getState().toString());

        return 2;
    }
}